<?php

use Illuminate\Database\Seeder;

class BaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        //清空院线、用户表数据库
        DB::table('chains')->delete();
        DB::table('users')->delete();
        DB::table('software_versions')->delete();

        //创建院线
        $chain = new \App\Chain();
        $chain->code = '100000000';
        $chain->name = '校园院线';
        $chain->province ='110000000';
        $chain->city = '110100000';
        $chain->address = '北京市海淀区花园路庚坊国际大厦9层';
        $chain->phone = '18210364952';
        $chain->fax = '';
        $chain->email = '825414435@qq.com';
        $chain->post_code = '100000';
        $chain->post_address = '北京市海淀区花园路庚坊国际大厦16层';
        $chain->recipient_name = 'wenquan';
        $chain->recipient_phone = '18210364952';
        $chain->status = 1;
        $chain->save();

        //创建初始的管理员用户
        $pilishen = new \App\User();
        $pilishen->account='xiaoyuanline';
        $pilishen->name ='校园院线';
        $pilishen->type = 1;
        $pilishen->email = 'xiaoyuanline@huaying.com';
        $pilishen->password = bcrypt('secret');
        $pilishen->chain_code = '10000000';
        $pilishen->is_manager = 1;
        $pilishen->save();


        //创建初始软件版本
        $software_version = new \App\SoftwareVersion();
        $software_version->name = '华夏电影售票软件';
        $software_version->version = 'V1.1';
        $software_version->manufacturer = '华夏电影';
        $software_version->release_date = \Carbon\Carbon::now();
        $software_version->test_date = \Carbon\Carbon::now();
        $software_version->register_date = \Carbon\Carbon::now();
        $software_version->install_date = \Carbon\Carbon::now();
        $software_version->update_date = \Carbon\Carbon::now();
        $software_version->MD5 = md5('华夏电影售票软件V0.1');
        $software_version->ftp_address = $software_version->ftp_username = $software_version->ftp_password;
        $software_version->update_MD5 = '';
        $software_version->status = 1;
        $software_version->save();

        $admin = \App\Role::where(['name'=>'超级管理员','type'=>1,'status'=>0])->first();
        $pilishen->attachRole($admin);
    }
}
